package com.lp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lp.dao.UserMapper;
import com.lp.entity.TestUser;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 添加
     *
     * @param testUser
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(TestUser testUser) {
        this.userMapper.insert(testUser);
        System.out.println(testUser.getId() + "=================");
//        this.userMapper.insert(user);
    }

    /**
     * 分页使用
     *
     * @return
     */
    public IPage<TestUser> page(int offset, int limit) {

        IPage<TestUser> list = this.userMapper.selectPage(new Page<>(offset, limit), new QueryWrapper<>());

        return list;
    }

}
